<template>
  <div class="container">
    <div class="input-group" v-if="SearchState">
      <input type="text" class="input-field" v-model="SearchValue" placeholder="请输入内容..." />
      <button class="submit-btn" @click="submit">搜索</button>
    </div>

    <div class="content">
      <h2 class="content-title">文章标题</h2>
      <div class="content-tags">
        <span class="tag" v-for="item in 2" :key="item" @click="onGroupingLink(item)">{{ `标签${item}` }}</span>
        <!-- 更多标签... -->
      </div>
      <div class="content-meta">
        <button @click="watchVideo(current.id)" class="meta-button watch-video">观看影片</button>
        <button @click="shareContent" class="meta-button share">分享</button>
      </div>
      <div class="content-share" v-if="state">
        <div class="shareinput-group">
          <input type="text" readonly v-model="shareLink" ref="sharelinkInput" class="shareinput-field" />
          <button @click="copyLink" class="sharesubmit-btn">复制链接</button>
        </div>
        <div class="social-buttons">
          <button @click="shareToLink(1)" class="social-button facebook">Facebook</button>
          <button @click="shareToLink(2)" class="social-button twitter">Twitter</button>
          <button @click="shareToLink(3)" class="social-button linkedin">LinkedIn</button>
        </div>
      </div>
      <div class="content-body">
        <p>这里是文章的简短描述或者引言...</p>
        <img src="/logo.png" alt="描述性文字" class="content-image" />
        <p>正文内容继续...在这里可以详细阐述文章的主题、观点、故事等内容。</p>
      </div>
    </div>

    <div class="grid-container">
      <div class="card" v-for="item in 20" :key="item" @click="onDetailLink(item)">
        <img src="/logo.png" alt="Card Image" class="card-img" />
        <div class="card-body">
          <div class="card-tags">
            <span class="tag" v-for="item in 2" :key="item" @click.stop="onGroupingLink(item)">{{ `标签${item}` }}</span>
            <!-- 添加更多标签 -->
          </div>
          <h3 class="card-title">卡片标题</h3>
          <p class="card-description">这里是一段描述文本，可以是关于卡片内容的简短介绍。</p>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
const router = useRouter();

const SearchState: any = useSearch();

const current = ref<any>({
  id: 1,
  alink: "https://vuejs.org/",
  blink: "https://router.vuejs.org/",
  clink: "https://pinia.vuejs.org/",
});

const onGroupingLink = (item: any) => {
  router.push({ path: `/grouping/${item}` });
};

const onDetailLink = (item: any) => {
  router.push({ path: `/appraise/${item}` });
};

const watchVideo = (id: any) => {
  router.push({ path: `/content/${id}` });
};

const state = ref(false);

const shareContent = () => {
  state.value = !state.value;
};

const shareToLink = (id: any) => {
  console.log(`分享到${id}`);
};

const shareLink = ref("https://www.baidu.com");
const linkInput = ref<any>();

const copyLink = async () => {
  console.log("复制成功");
  // console.log(linkInput.value.value);
  if (linkInput.value) {
    // 创建一个临时的textarea元素来辅助复制操作
    const textarea = document.createElement("textarea");
    textarea.value = shareLink.value;
    document.body.appendChild(textarea);
    textarea.select();
    try {
      // 尝试执行复制命令
      document.execCommand("copy");
      alert("内容已复制到剪贴板！");
    } catch (err) {
      console.error("复制失败:", err);
    }
    document.body.removeChild(textarea);
  }
};

const SearchValue = ref("");

const submit = () => {
  console.log(SearchValue.value);
  router.push({ path: `/search/${SearchValue.value}` });
};
</script>

<style scoped>
.container {
  width: 1600px;
  margin: 20px auto;
  max-width: 100%;
  box-sizing: border-box;
}

.content {
  max-width: 800px;
  margin: 0 auto;
}

.content-title {
  font-size: 24px;
  margin-bottom: 10px;
}

.content-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-bottom: 20px;
}

.tag {
  background-color: #f1f1f1;
  color: #333;
  padding: 5px 10px;
  border-radius: 5px;
  font-size: 0.9em;
}

.content-body {
  text-align: justify;
}

.content-image {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 20px 0;
}

.tag:hover {
  cursor: pointer;
  background-color: #007bff; /* 或者你喜欢的高亮颜色 */
  color: #fff; /* 文字颜色，确保在高亮背景下可读 */
}

.grid-container {
  display: grid;
  grid-template-columns: repeat(4, 1fr); /* 这里定义了4列，每列宽度相等 */
  grid-gap: 20px; /* 设置网格之间的间隔，可根据需要调整 */
  margin-top: 50px;
}

.card-title {
  margin: 0 0 8px 0;
  font-size: 1.2em;
  color: #333;
}

.card-description {
  color: #666;
  line-height: 1.5;
}

.card {
  border-radius: 10px;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  margin-bottom: 20px;
  overflow: hidden; /* 确保图片尺寸不会超出卡片边界 */
}

.card-img {
  width: 100%;
  height: auto;
  display: block;
}

.card-body {
  padding: 16px;
}

.card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 8px;
}

.tag {
  background-color: #f1f1f1;
  color: #333;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 0.9em;
}

.card:hover {
  cursor: pointer;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
  transform: scale(1.05);
}

.meta-button {
  background-color: #007bff;
  color: white;
  border: none;
  padding: 5px 10px;
  cursor: pointer;
  border-radius: 5px;
  margin-right: 5px;
  font-size: 0.9em;
}

.meta-button:hover {
  background-color: #0056b3;
}

.watch-video {
  /* 可以根据需要添加特定于观看视频按钮的样式 */
}

.share {
  /* 可以添加特定于分享按钮的样式 */
}

.content-share {
  margin-top: 20px;
}

.readonly-link {
  width: 100%;
  padding: 10px;
  margin-bottom: 10px;
  border: 1px solid #ccc;
  outline: none;
}

.copy-button {
  background-color: #007bff;
  color: white;
  border: none;
  padding: 5px 10px;
  cursor: pointer;
  border-radius: 5px;
}

.social-buttons {
  display: flex;
  justify-content: flex-start;
}

.social-button {
  background-color: #f1f1f1;
  color: #333;
  border: none;
  padding: 10px 15px;
  cursor: pointer;
  border-radius: 5px;
  text-align: center;
  margin-right: 10px;
}

/* 为不同的社交按钮添加颜色 */
.facebook {
  background-color: #3b5998;
}

.twitter {
  background-color: #1da1f2;
}

.linkedin {
  background-color: #0077b5;
}

.shareinput-group {
  position: relative;
  width: 400px;
  /* margin: 20px auto; */
  margin-bottom: 20px;
}

.shareinput-field {
  width: 300px;
  padding: 15px 20px;
  border-radius: 5px;
  border: 1px solid #ddd;
  outline: none;
  box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.05);
  font-size: 14px;
  transition: all 0.3s ease;
}

.shareinput-field:focus {
  border-color: #007bff;
  box-shadow: 0 0 5px rgba(0, 123, 255, 0.3);
}

/* 按钮样式 */
.sharesubmit-btn {
  position: absolute;
  right: 0;
  top: 0;
  width: 100px;
  height: 100%;
  padding: 0 20px;
  border: none;
  outline: none;
  background-color: #007bff;
  color: white;
  cursor: pointer;
  border-radius: 0 5px 5px 0;
  font-size: 14px;
  transition: all 0.3s ease;
}

.sharesubmit-btn:hover {
  background-color: #0056b3;
}

/* 输入框聚焦时按钮效果 */
.shareinput-field:focus + .sharesubmit-btn {
  background-color: #0056b3;
}









.input-group {
  position: relative;
  width: 700px;
  margin: 20px auto;
}

.input-field {
  width: 600px;
  padding: 15px 20px;
  border-radius: 25px;
  border: 1px solid #ddd;
  outline: none;
  box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.05);
  font-size: 14px;
  transition: all 0.3s ease;
}

.input-field:focus {
  border-color: #007bff;
  box-shadow: 0 0 5px rgba(0, 123, 255, 0.3);
}

/* 按钮样式 */
.submit-btn {
  position: absolute;
  right: 0;
  top: 0;
  width: 100px;
  height: 100%;
  padding: 0 20px;
  border: none;
  outline: none;
  background-color: #007bff;
  color: white;
  cursor: pointer;
  border-radius: 0 25px 25px 0;
  font-size: 14px;
  transition: all 0.3s ease;
}

.submit-btn:hover {
  background-color: #0056b3;
}

/* 输入框聚焦时按钮效果 */
.input-field:focus + .submit-btn {
  background-color: #0056b3;
}
</style>
